list1 = [1,2,3,4,5]
list2 = ["hello","good","nice","haha"]
set3 = {True,False,None,0}
zipobj = zip(list1,list2,set3)  # 打包

# print(zipobj) # 这是一个包,显示的是包所在的地址 <zip object at 0x00000149CFFFAB48>

print(list(zipobj)) #可以将包转化为列表,查看包中的内容
'''打印结果为 [(1, 'hello', False), (2, 'good', True), (3, 'nice', None)]'''


'''解包操作 zip(* 包名zipobj ) '''
zipobj = zip(list1, list2, set3)  # 打包
'''解包 显示的也是一串地址 <zip object at 0x000001B34E5FAB88>'''
# print(zip(*zipobj))

# 若想查看解包的内容,可使用for循环打印(需将上一步print注释,因为上一步中已经解包)
# for i in zip(*zipobj):
#     print(i)
'''打印结果
(1, 2, 3)
('hello', 'good', 'nice')
(False, True, None) '''
zipobj = zip(list1, list2, set3)  # 打包
x,y,z=zip(*zipobj)                #解包赋值
print(x)                          #(1, 2, 3)
print(y)                          #('hello', 'good', 'nice')
print(z)                          #(False, True, None)




import numpy as np
a=[1,2,3,4,5]
b=(1,2,3,4,5)
c=np.arange(5)
d="zhang"
zz=zip(a,b,c,d)
print(list(zz))
'''
输出：
[(1, 1, 0, 'z'), (2, 2, 1, 'h'), (3, 3, 2, 'a'), (4, 4, 3, 'n'), (5, 5, 4, 'g')]
'''


#当参数长度不一时，zip和较短的保持一致，itertools.zip_longest()和较长的保持一致。
'''不够的调用itertools中的zip_longest添加0来补充 '''
print("\n________________________________________________________")
from itertools import zip_longest

# xpts = [1, 5, 4, 2, 17]
# ypts = [101, 78, 37, 15, 62, 99]
# for x, y in zip(xpts, ypts):
#     temp = (x, y)
#     print(temp)

print('-'*50)
a = [1, 2, 3]
b = ['w', 'x', 'y', 'z']

for i in zip_longest(a, b, fillvalue=0):
    print(i)
# (1, 'w')
# (2, 'x')
# (3, 'y')
# (0, 'z')
for i in zip_longest(a, b):  #不加fillvalue 默认补None
    print(i)
# (1, 'w')
# (2, 'x')
# (3, 'y')
# (None, 'z')
c=[[1, 2, 3],[1,2,3],[1,2]]
# for i in zip_longest(c ,fillvalue= 0 ):
#      print(i)
a = (1, 2, 3)
b = (10, 20, 30)
L = list(zip(a, b))
print(f"obj = {L}")
c, d = list(zip(*L))  # 使用*解压序列
print(f"c = {c} \nd = {d}")
if a == c and b == d:
    print("两次 zip() 等于啥都没干......")
